home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / ACORNUSERS / EMULATOR / V2600 / !v2600 / c / arc_disp next >
Text File  |  1998-06-06  |  5KB  |  189 lines

  1. /****************************************************************************
  2.  
  3.    This file is part of x2600, the Atari 2600 Emulator
  4.    ===================================================
  5.  
  6.    Copyright 1996 Alex Hornby. For contributions see the file CREDITS.
  7.  
  8.    ***Modified Wed 8th April, 1998 by Ian Molton
  9.  
  10.    This software is distributed under the terms of the GNU General Public
  11.    License. This is free software with ABSOLUTELY NO WARRANTY.
  12.  
  13.    See the file COPYING for details.
  14.  
  15.    $Id: svga_disp.c,v 1.2 1996/08/26 15:04:20 ahornby Exp $
  16. ****************************************************************************/
  17.  
  18. #include "config.h"
  19. #include "version.h"
  20.  
  21. /*
  22.    The ACORN display code.
  23. */
  24.  
  25. /* Standard Includes */
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include "string.h"
  29. #include "swis.h"
  30.  
  31. /* My headers */
  32. #include "types.h"
  33. #include "vmachine.h"
  34. #include "colours.h"
  35. #include "hawklib.h"
  36.  
  37. /* Various variables */
  38. extern int wimp;
  39. extern int *arc_sprite_area;
  40. extern int *wimp_block;
  41.  
  42. extern void scan_controls(void);
  43. extern Window *main_window;
  44.  
  45. int mode_save_block[256];
  46.  
  47. /* Start of image data */
  48. BYTE *vscreen;
  49. int graph_mem = 0;
  50. extern int redrawn;
  51.  
  52. /* The width and height of the image, including any magnification */
  53. int vwidth, vheight, theight;
  54.  
  55. /* size of display in bytes */
  56. static int bytesize;
  57.  
  58. /* Translates a 2600 color value into an X11 pixel value */
  59. /* b: byte containing 2600 colour value */
  60. /* returns: X11 pixel value */
  61. int tv_color(BYTE b){
  62.   return (b >> 1);
  63. }
  64.  
  65. void reenter_desktop(void){
  66.   /* Re enter saved mode */
  67.   _swi(OS_ScreenMode,_IN(0)|_IN(1), 0, mode_save_block);
  68.  
  69.   /* Redraw screen */
  70.   _swi(Wimp_ForceRedraw, _INR(0,4), -1, 0, 0, 0x7fffffff, 0x7fffffff);
  71.  
  72.   /* Re-enable pointer */
  73.   system("pointer 1"); // YUCK!
  74. }
  75.  
  76. void leave_desktop(void){
  77.   int block[2];
  78.   int coltab[256];
  79.   int modeblock[11];
  80.   int i;
  81.   int *mode_save_temp;
  82.  
  83.   /* store desktop mode */
  84.  
  85.     _swi(OS_ScreenMode, _IN(0)|_OUT(1), 1, &mode_save_temp);
  86.     i = 0;
  87.     while((i < 255) && (mode_save_temp[i] != -1)){
  88.       mode_save_block[i] = mode_save_temp[i];
  89.       i++;
  90.     }
  91.     mode_save_block[i] = -1;
  92.  
  93.   /* Set up screen mode */
  94.   modeblock[ 0] = 1;
  95.   modeblock[ 1] = 320;
  96.   modeblock[ 2] = 256;
  97.   modeblock[ 3] = 3;
  98.   modeblock[ 4] = -1;
  99.   modeblock[ 5] = 3;
  100.   modeblock[ 6] = 255;
  101.   modeblock[ 7] = 0;
  102.   modeblock[ 8] = 128;
  103.   modeblock[ 9] = -1;
  104.   modeblock[10] = -1;
  105.   _swi(OS_ScreenMode,_IN(0)|_IN(1), 0, modeblock);
  106.  
  107.   /* Get screen base address */
  108.   block[0] = 148;
  109.   block[1] = -1;
  110.   _swi(OS_ReadVduVariables,_IN(0)|_IN(1),block,block);
  111.   graph_mem = block[0];
  112.  
  113.   /* Set up a colour table */
  114.   for(i = 0; i<256; i++){
  115.     coltab[i] =  ((colortable[i*2] & 0x00FF0000) >> 8) + /* Red */
  116.                  ((colortable[i*2] & 0x0000FF00) << 8) + /* Green */
  117.                  ((colortable[i*2] & 0x000000FF) << 24); /* Blue */
  118.   }
  119.   _swi(ColourTrans_WritePalette,_IN(0)|_IN(1)|_IN(2)|_IN(3)|_IN(4)|_IN(5),-1,-1,coltab,0,0,0);
  120.  
  121.   /* rock and roll */
  122. }
  123.  
  124. /* Turns on the television. */
  125. /* argc: argument count */
  126. /* argv: argument text */
  127. /* returns: 1 for success, 0 for failure */
  128. int
  129. tv_on (int argc, char **argv)
  130. {
  131.   /* TV size */
  132.   tv_height = 256;
  133.   bytesize = tv_height * 320;
  134.   vwidth = tv_width * 2;
  135.   theight = tv_height;
  136.   vheight = theight;
  137.  
  138.   /* allocate screen buffer. (part of a sprite now) */
  139.   if ((vscreen = (BYTE *) malloc (bytesize)) == NULL){
  140.     hl_error("Out of memory!");
  141.     exit(0);
  142.   }
  143.   memset(vscreen, 0, bytesize);
  144.   return (1);
  145. }
  146.  
  147. /* Displays the tv screen */
  148. void tv_display (void){
  149.   if(wimp){
  150.     int left;
  151.     /* wimp_display routine */
  152.     /* force redraw */
  153.     if(redrawn == 0){
  154.       memcpy ((char *)arc_sprite_area + 0x83C, vscreen, bytesize);
  155.       wimp_block[0] = main_window->handle;
  156.       wimp_block[1] = 0;
  157.       wimp_block[2] = -512;
  158.       wimp_block[3] = 640;
  159.       wimp_block[4] = 0;
  160.       _swi(Wimp_UpdateWindow, _IN(1)|_OUT(0), wimp_block, &left);
  161.       while(left) _swi(Wimp_GetRectangle, _IN(1)|_OUT(0), wimp_block, &left);
  162.       redrawn = 1;
  163.     }
  164.   }
  165.   else{  /* Non-Wimp redraw code */
  166.     if(graph_mem) memcpy ((char *)graph_mem, vscreen, bytesize);
  167.     /* Woo - hoo */
  168.   }
  169. }
  170.  
  171. /* The Event code. */
  172. void tv_event (void){
  173.   if(!wimp) scan_controls();
  174. }
  175.  
  176. /* Single pixel plotting function. Used for debugging,  */
  177. /* not in production code  */
  178. /* x: horizontal position */
  179. /* y: vertical position */
  180. /* value: pixel value */
  181. void tv_putpixel (int x, int y, BYTE value){
  182.   BYTE *p;
  183.   x = x << 1;
  184.   p = vscreen + x + y * vwidth;
  185.   *(p) = value;
  186.   *(p + 1) = value;
  187. }
  188.  
  189.